package cz.su.pod.reservation;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cz.su.pod.reservation.domain.LdapUser;
import cz.su.pod.reservation.ldap.LDAPClient;
import cz.su.pod.reservation.ldap.LDAPClientImpl;

public class AppContextLoaderListener implements ServletContextListener {
	private final Logger log = LoggerFactory.getLogger(getClass());
	
	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		log.info("Initializing Pod-O-Lee Reservation application context");
		
		LDAPClient client = (LDAPClient) SpringBean.getBean(LDAPClient.class);
		LdapUser user = client.login("gros", ".");
		log.debug(user != null ? user.toString() : "FAIL");
		
		log.info("Pod-O-Lee Reservation application context intialized successfuly");
	}

}
